package com.enjoy.concurrent.ch5;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.concurrent.*;

@Slf4j(topic = "enjoy")
public class ArrayBlockingQueueTest {

    @Test
    public void test1() {
        BlockingQueue<Integer> blockingQueue = new ArrayBlockingQueue<>(10);

        blockingQueue.add(1);
        blockingQueue.element();
        blockingQueue.remove();
    }

    @Test
    public void test2() {
        BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);
        blockingQueue.offer("a");
        blockingQueue.peek();
        blockingQueue.element();
        String s = blockingQueue.poll();
        System.out.println(s);
    }

    @Test
    public void test3() throws InterruptedException {
        BlockingQueue<String> blockingDeque = new ArrayBlockingQueue<>(2);

        blockingDeque.put("aa");

        blockingDeque.take();
    }

    @Test
    public void test4() {
        // 可以当做栈来使用
        BlockingDeque<String> blockingDeque = new LinkedBlockingDeque<>();
        blockingDeque.push("a");
        String s = blockingDeque.pop();
        System.out.println(s);
    }

    @Test
    public void test5() {
        // 无界队列
        BlockingQueue<String> blockingDeque = new LinkedBlockingQueue<>();
        blockingDeque.offer("a");
        String s = blockingDeque.poll();
        System.out.println(s);
    }


}
